package com.b511.swpu.cementbackend;

import com.b511.swpu.cementbackend.entity.BA_SpecialStratum;
import com.b511.swpu.cementbackend.entity.BA_Well;
import com.b511.swpu.cementbackend.entity.BA_WellStructure;
import com.b511.swpu.cementbackend.entity.CM_WorkBaseInfo;
import com.b511.swpu.cementbackend.repository.BA_WellRepository;
import com.b511.swpu.cementbackend.repository.BA_WellStructureRepository;
import com.b511.swpu.cementbackend.repository.CM_WorkBaseInfoRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest
public class DataSync {
    @Autowired
    BA_WellRepository wellRepository;

    @Autowired
    BA_WellStructureRepository wellStructureRepository;

    @Test
    public void sync(){
        // 逐行校验 wellName, ba_well_id
        List<BA_WellStructure> wellStructureList = wellStructureRepository.findAll();
        System.out.println(wellStructureList.size());
        for (int itreator = 0; itreator < wellStructureList.size(); itreator++) {
            String tmpWellName = wellStructureList.get(itreator).getWellName();
            if (null != wellRepository.findByWellName(tmpWellName)){
                wellStructureList.get(itreator).setWell(wellRepository.findByWellName(tmpWellName));
            }else {
                System.out.println("数据对应的井为空！" + wellStructureList.get(itreator).getBA_Well_Structure_ID());
            }
        }
        wellStructureRepository.saveAll(wellStructureList);
    }

}
